﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    if(shouldcircle)
    {
        painter.drawEllipse(pos,40,40);
    }
    else
    {
        pre_pos.setX(40);
        pre_pos.setY(40);
        painter.drawEllipse(pre_pos,40,40);
    }
}

void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    pos=event->pos();
    //判断鼠标是不是在圆上面
    if(pow(pos.x()-pre_pos.x(),2)+pow(pos.y()-pre_pos.y(),2)<=40*40)
    {
        shouldcircle=true;
        pre_pos=pos;
        repaint();
    }

}
